package com.wolfalpha.utron.activity.base;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.umeng.analytics.MobclickAgent;
import com.wolfalpha.utron.R;
import com.wolfalpha.utron.app.AppManager;

import java.util.Map;

/**
 * 包含了头部左侧和中部以及右部的Activity
 * <p/>
 * Created by luodon on 15/8/18.
 */
public class BaseNormal2Activity extends Activity {

    private ImageView ivBack;               //返回按钮
    private TextView tvTitle;               //标题
    private ImageView ivRight;              //右侧的操作

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        AppManager.getAppManager().addActivity(this);
    }

    /**
     * 初始化头部界面
     */
    public void initHead() {
        ivBack = (ImageView) findViewById(R.id.header_iv_back);
        tvTitle = (TextView) findViewById(R.id.header_tv_title);
        ivRight = (ImageView) findViewById(R.id.header_iv_right);

        ivBack.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
        ivRight.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                rightOperation();
            }
        });
    }

    /**
     * 在子类的onCreate中调用
     *
     * @param title
     */
    public void setTvTitle(String title) {
        initHead();
        tvTitle.setText(title);
    }

    /**
     * 设置右侧的图标
     * <p/>
     * 默认为app_operation
     *
     * @param icon
     */
    public void setRightIcon(int icon) {
        ivRight.setImageResource(icon);
    }

    /**
     * 设置右侧操作显示
     *
     * @param visiable
     */
    public void setRightVisiable(boolean visiable) {
        ivRight.setVisibility(visiable ? View.VISIBLE : View.INVISIBLE);
    }

    private Map<String, Long> keyTimes;      //点击时间记录

    /**
     * 留给父类实现
     * <p/>
     * 点击右侧按钮时触发
     */
    public void rightOperation() {


    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        AppManager.getAppManager().finishActivity(this);
    }

    public void onResume() {
        super.onResume();
        //友盟统计
        MobclickAgent.onResume(this);
    }

    public void onPause() {
        super.onPause();
        //友盟统计
        MobclickAgent.onPause(this);
    }
}
